layui.define(['element'],function(exports){

    var $ = layui.$;
    $('.input-field').on('change',function(){
        var $this = $(this),
            value = $.trim($this.val()),
            $parent = $this.parent();

        if(value !== '' && !$parent.hasClass('field-focus')){
            $parent.addClass('field-focus');
        }else{
            $parent.removeClass('field-focus');
        }
    })


    //点击登录
    $('.login-button').click(function () {
        var userName = $("#userName").val();
        var pwd = $("#password").val();
        var login_data = {
            userName:userName,
            pwd:pwd
        };
        if(userName==''||pwd=="") {
            /*$("#msg").html('用户名不能为空！');*/
        } else {
            $.post('../check/check-login',login_data,function (info) {
                console.log(info);
                /*alert("测试");*/
                if ("success" == info.msg) {
                    /*alert("登录成功！");*/
                    window.location.href = '../../views/index.jsp';
                } else {
                    element.init();
                    layer.msg("用户名或密码错误，请确认后重新登录！");
                }
            });
        }
    });

    exports('login');
});